<?php

namespace app\factory\controller;

use app\common\respond\HttpApi;
use app\factory\logic\PigLogic;

class PigController
{
    /**
     * @Description 新增/编辑
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/12 10:45:10
     * @return \think\response\Json
     */
    public function addEdit(HttpApi $respond)
    {
        $param = [
            'Id' => request()->post('Id'),
            'FenceId' => request()->post('FenceId'),
            'TagAddress' => request()->post('TagAddress'),
            'Health' => request()->post('Health'),
            'Weight' => request()->post('Weight'),
            'IsTempOut' => request()->post('IsTempOut'),
            'EntryTime' => request()->post('EntryTime'),
            'ExitTime' => request()->post('ExitTime') ?: 0,
            'ExitRemark' => request()->post('ExitRemark') ?: "",
            'FeedBaseTime' => request()->post('FeedBaseTime'),
            'FeedPreDayId' => request()->post('FeedPreDayId') ?: 0,
            'isLoop' => request()->post('isLoop'),
            'Breed' => request()->post('Breed'),
            'RecordTime' => request()->post('RecordTime'),
        ];
        $rule = [
            'Id' => 'require|integer|>:0',
            'ExitTime' => 'integer|>=:0',
            'ExitRemark' => 'max:255',
            'RecordTime' => 'require|integer|>:0',
        ];
        validate($rule)->check($param);

        $logic = new PigLogic();
        $data = $logic->addEdit($param['Id'],$param);

        return $respond->success([]);
    }

    /**
     * @Description 生猪批次
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/12 11:27:09
     * @return \think\response\Json
     */
    public function batch(HttpApi $respond)
    {
        $param = [
            'PigId' => request()->post('PigId'),
            'Date' => request()->post('Date')
        ];
        $rule = [
            'PigId' => 'require|integer|>:0',
            'Date' => 'require|dateFormat:Y-m-d'
        ];
        validate($rule)->check($param);

        $logic = new PigLogic();
        $data = $logic->batch($param['PigId'],$param['Date']);

        return $respond->success([]);
    }

}